package com.yisoo.rs.rsmovie.entity;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;

import com.yisoo.rs.common.vo.MovieJsonVo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * 
 * 
 * @author mmciel
 * @email 761998179@qq.com
 * @date 2021-12-03 17:03:59
 */
@Data
@TableName("movies_director")
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class DirectorEntity implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * ID
	 */
	@TableId
	private Long directorId;
	/**
	 * 名字
	 */
	private String directorName;

	private Long appId;
	public static List<DirectorEntity> generatorByMovieJsonVo(Long appId, List<MovieJsonVo> dataList){
		HashSet<String> stars = new HashSet<>();
		for (MovieJsonVo m : dataList) {
			stars.addAll(new HashSet<>(m.getMvDirector()));
		}
		return stars.stream().map(temp -> new DirectorEntity(null, temp, appId)).collect(Collectors.toList());
	}
    public static List<DirectorEntity> generatorByMovieJsonVo_bak(Long appId,List<MovieJsonVo> dataList, Map<String,Integer> reIndex) {
//		编制反向索引
		HashSet<String> stars = new HashSet<>();
//		单个变量临时存储
		DirectorEntity temp = null;
//		要反回的结果集
		List<DirectorEntity> res = new ArrayList<>();
		int tempIndex = 0;
		for (MovieJsonVo m : dataList) {
			HashSet<String> tempSet = new HashSet<>(m.getMvDirector());
//			由于每一个电影有，所以要对集合进行遍历插入
			for (String s : tempSet){
				if (!stars.contains(s)){
					temp = new DirectorEntity(null,s,appId);
					res.add(temp);
					reIndex.put(temp.getDirectorName(),tempIndex++);
				}
			}
			stars.addAll(tempSet);
		}
		return res;
    }

}
